﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MusicOnLine.Models;

namespace MusicOnLine.Handler
{
    /// <summary>
    /// Common 的摘要说明
    /// </summary>
    public class Common : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("Cache-Control", "no-cache,must-revalidate");
            string action = context.Request.Params["action"];
            if (!string.IsNullOrEmpty(action))
            {
                this.GetType().GetMethod(action).Invoke(this, new object[] { context });
            }
            context.Response.End();
        }

        public void IncreasePlayCont(HttpContext context)
        {
            int ID = Convert.ToInt32(context.Request["ID"]);
            MusicPlayEntities db = new MusicPlayEntities();
            AACInfo song = db.AACInfoes.Single(obj => obj.ID == ID);
            song.PlayedCount = song.PlayedCount + 1;         
            db.SaveChanges();
            context.Response.Write(song.PlayedCount);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}